export function debounce(func, wait, immediate = false) {
	let timeout;

	return function(...args) {
		const context = this;

		// 定义一个函数用于调用原函数
		const later = function() {
			timeout = null;
			if (!immediate) {
				func.apply(context, args);
			}
		};

		const callNow = immediate && !timeout;

		// 清除之前的定时器
		clearTimeout(timeout);

		// 设置新的定时器
		timeout = setTimeout(later, wait);

		if (callNow) {
			func.apply(context, args);
		}
	};
}
